#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Created on 23.10.2012

@author: niimailtah
"""

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

from app.sharedtools.qtsingleapplication import QtSingleApplication
from extentionsystem.pluginmanager import PluginManager

if __name__ == '__main__':
    print 'Starting PyQWiki...'
    appNameC = 'PyQWiki'
    corePluginNameC = 'Core'
    appGuid = 'F3FF80BA-BA05-4277-8063-82A6DB9245A2'
    app = QtSingleApplication(appGuid, sys.argv)
    if app.isRunning(): sys.exit(0)

    pluginManager = PluginManager()
    pluginManager.setPluginPaths(["./plugins/",])

    plugins = pluginManager.plugins()
    coreplugin = None
    for spec in plugins:
        if corePluginNameC == spec.name():
            coreplugin = spec
            break

    if not coreplugin:
        sys.exit(1)

    pluginManager.loadPlugins()

    window = QWidget()
    window.setWindowTitle(appNameC)
    window.resize(300, 70)
    btnQuit = QPushButton("&Close window")
    label = QLabel("<font color=red size=72><b>" + appNameC + "</b></font>")
    vbox = QVBoxLayout()
    vbox.addWidget(label)
    vbox.addWidget(btnQuit)
    window.setLayout(vbox)
    QObject.connect(btnQuit, SIGNAL("clicked()"), qApp, SLOT("quit()"))
    window.show()
    app.setActivationWindow(window)
    sys.exit(app.exec_())
